import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/index.js'

import Join from '../views/Join/Join.vue'
import Admin from '../views/admin/Admin.vue'

Vue.use(VueRouter)

  const routes = [
	{
		path: '',
		redirect: 'Join/Start',
		meta: {
			title: 'Hey!动漫社'
		}
	},{
    path: '/Join',
    name: 'Join',
    component: Join,
		meta: {
			title: 'Hey!动漫社'
		},
		children:[
			{
				path: '',
				redirect: 'Intro',
				meta: {
					title: 'Hey!动漫社'
				}
			},
			{
				path: 'Intro',
				component: () => import('../views/Join/Intro.vue'),
				meta: {
					title: 'Hey!动漫社'
				}
			},{
				path: 'Register',
				component: () => import('../views/Join/Register.vue'),
				meta: {
					title: '新社员注册'
				}
			},{
				path: 'Start',
				component: () => import('../views/Join/Start'),
				meta: {
					title: 'Hey!动漫社'
				}
			}
		]
  },{
		path:'/Admin',
		name: 'Admin',
		component: Admin,
		meta: {
			title: 'Hey!动漫社'
		},
		children:[
			{
				path: '',
				redirect: 'Login'
			},{
				path: 'Login',
				beforeEnter:(to,from,next) => {
					store.state.isLogin ? next('/Admin/Show') : next()
				},
				component: () => import('../components/Login.vue'),
				meta: {
					title: '登录'
				}
			},{
				path: 'Show',
				component: () => import('../views/admin/Show.vue'),
				meta: {
					title: 'Hey!动漫社'
				}
			}
		]
	}
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router


const originalPush = VueRouter.prototype.push
	 VueRouter.prototype.push = function push(location) {
	 return originalPush.call(this, location).catch(err => err)
}
